import axios from 'axios';
import { getData } from './auth'
const service = axios.create({
    baseURL: '',
    timeout: 10000
})

// 请求开始前拦截设置请求头
service.interceptors.request.use(
    config => {
        if(getData('token')) {
            config.headers['Authorization'] = 'Bearer ' + getData('token');
        }
        config.headers['Content-Type'] = 'application/json'
        return config
    },
    error => {
        Promise.reject(error);
    }
)

// 拦截器
service.interceptors.response.use(
    response => {
        return response.data
    },
    error => {
        return Promise.reject(error)
    }
)

export default service;